package com.artPreter.service.impl;


import com.artPreter.mapper.RegionMapper;
import com.artPreter.pojo.Region;
import com.artPreter.pojo.Region;
import com.artPreter.service.IRegionService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 区域表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2024-12-05
 */
@Service
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> implements IRegionService {

    @Override
    public IPage<Region> getPage(Integer currentPage, Integer size, Region region) {
        IPage<Region> regionIPage = new Page<>(currentPage, size);
        LambdaQueryWrapper<Region> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Region::getStatus,1);
        queryWrapper.ne(Region::getType,3);
        if(region.getCityname()!=null&&!"".equals(region.getCityname())){
            queryWrapper.like(Region::getCityname,region.getCityname());
        }
        regionIPage = this.baseMapper.selectPage(regionIPage, queryWrapper);
        return regionIPage;
    }


    @Override
    public void add(Region region) {
        region.setStatus(1);
        // 生成UUID并设置到实体对象中
        this.baseMapper.insert(region);
    }

    @Override
    public void edit(Region region) {
        this.baseMapper.updateById(region);
    }

    @Override
    public void delete(Region region) {
        this.baseMapper.deleteById(region.getId());
    }

    @Override
    public List<Region> getList(Region region) {
        LambdaQueryWrapper<Region> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Region::getStatus,1);
        queryWrapper.ne(Region::getType,3);
        if(region.getType()==null){
            queryWrapper.eq(Region::getType,1);
        }
        if(region.getCityname()!=null&&!"".equals(region.getCityname())){
            queryWrapper.like(Region::getCityname,region.getCityname());
        }
        List<Region> result= this.baseMapper.selectList(queryWrapper);
        return result;
    }
}
